#pragma once

#include <memory>
#include <string>

namespace bamboo {

class Logger;
typedef std::shared_ptr<Logger> Logger_ptr;

//日志级别
class LogLevel {
public:
    enum Level {
        DEBUG = 1,
        INFO,
        WARN,
        ERROR,
        FATAL
    };
};


/**
 * @brief 日志事件
 */
class LogEvent {
public:
    typedef std::shared_ptr<LogEvent> ptr;
    LogEvent(Logger_ptr logger, LogLevel::Level level, const char* file, int32_t line, uint32_t elapse, 
        uint32_t thread_id, uint32_t fiber_id, uint64_t time, 
        const std::string& thread_name, const std::string& content);

    Logger_ptr getLogger() const { return m_logger; }
    LogLevel::Level getLevel() const { return m_level; }
    const std::string& getFile() const { return m_file; }
    int32_t getLine() const { return m_line; }
    uint32_t getElapse() const { return m_elapse; }
    uint32_t getThreadId() const { return m_threadId; }
    uint32_t getFiberId() const { return m_fiberId; }
    uint64_t getTime() const { return m_time; }
    const std::string& getThreadName() const { return m_threadName; }
    const std::string& getContent() const { return m_content; }

private:
    Logger_ptr m_logger;
    LogLevel::Level m_level;
    const char* m_file;       //文件名
    int32_t     m_line = 0;             //行号
    uint32_t    m_elapse = 0;           //程序启动开始到现在的毫秒数
    uint32_t    m_threadId = 0;         //线程id
    uint32_t    m_fiberId = 0;          //协程id
    uint64_t    m_time = 0;             //时间戳
    std::string m_threadName;           //线程名
    std::string m_content;              //日志内容
};


class LogEventWrap {
public:
    LogEventWrap(LogEvent::ptr e);
    ~LogEventWrap();
    LogEvent::ptr getEvent() const { return m_event; }

private:
    LogEvent::ptr m_event;
};

}